home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / e / StdErr.lha / StdErr / StdErr.DOC next >
Encoding:
Text File  |  1994-04-09  |  9.4 KB  |  265 lines

  1. Document StdErr
  2.  
  3. StdErr.E is a product of the Cheese Olfactory Workshop.  Eat your greens.
  4.  
  5. 0. Distributability
  6. -------------------
  7.  
  8. If you were able to get this, you may use it.  If you are willing to
  9. distribute it FREE OF CHARGE, by all means distribute it.  I would ask,
  10. for the sake of following your own conscience, that if you MUST charge
  11. someone money for this, that you not charge more than DevCon would charge
  12. for their PD disks (roughly $5 US or less a disk).
  13.  
  14. 1. Usage
  15. --------
  16.  
  17. Very simple, really.. all depending on your needs.
  18.  
  19. First thing to remember, however, is that you must err_Dispose() by the
  20. end of your program (or, at LEAST err_Close().. but err_Dispose() is the
  21. recommended method to use).  If you fail to do this, you will leave a
  22. filehandle open (possibly), which would be very bad... it could also waste
  23. memory to do so.
  24.  
  25. The next thing to remember is that StdErr.E really works best with EPP. 
  26. EPP can make your life very easy.  It's truly a remarkable program.  If
  27. you're an E programmer working without EPP, you're making your life more
  28. difficult than necessary.  Insure you download the very latest version of
  29. this useful utility by Barry Wills.  Amusingly, I did not use EPP to 
  30. write StdErr.E.
  31.  
  32. Otherwise...
  33.  
  34. 1.1. stderr.filename
  35. --------------------
  36.  
  37. If you want to change where your error messages are sent, you may reassign
  38. stderr.filename wherever you want the messages to go.  For example:
  39.  
  40. stderr.filename:='RAM:error.txt'
  41.  
  42. will cause it to be appended to a file called 'error.txt' in the RAM:
  43. (yes, StdErr.E automatically appends messages to files, rather than
  44. overwriting the file).
  45.  
  46. stderr.filename:=stdout
  47.  
  48. will direct error messages to the stdout filehandler.  It is the only case
  49. where a filehandler may be used instead of a string.
  50.  
  51. stderr.filename:='CONSOLE:'
  52.  
  53. will direct error messages to the stderr port (like C does).  That is, if
  54. run from a shell, it'll print its messages to the shell, rather than to
  55. any potentially redirected output (eg. if someone typed 'command >moo.txt'
  56. the errors would not go into moo.txt, but to the console instead).
  57.  
  58. 1.2. err_New(filename)
  59. ----------------------
  60.  
  61. VOID err_New(LONG filename)
  62.  
  63. err_New() takes one argument, a string pointer (?) that will be inserted as
  64. the filename for the stderr port.
  65.  
  66. err_New() does NOT open a file.. it only allocates storage for the stderr
  67. port.  It is intended to be used if the stderr port is to be initialized
  68. to a particular area prior to writing any error messages (that is, you
  69. already know you want your error messages to go to, say, 'ram:boo.bob', so
  70. you use err_New('ram:boo.bob') to prepare the program to do so).
  71.  
  72. You may want to read `stderr.filename' for more information.
  73.  
  74. 1.3. err_Close()
  75. ----------------
  76.  
  77. VOID err_Close(VOID)
  78.  
  79. err_Close() takes no arguments... in fact, you should really avoid using
  80. it.  If E were C++, I would have hidden this as a private method.  As it
  81. is, you COULD use it, but I don't recommend it.
  82.  
  83. But, for the curious, err_Close() will close the filehandle (if it is safe
  84. to do so).
  85.  
  86. I would STRONGLY recommend using `err_Dispose()' instead of this command.
  87.  
  88. 1.4. err_Dispose()
  89. ------------------
  90.  
  91. VOID err_Dispose(VOID)
  92.  
  93. This command will safely close the filehandle used by `err_Close()', and
  94. Dispose() of all bits of memory allocated earlier.  You really should use
  95. this command at the end of your application, just before exiting, in order
  96. to safely close the filehandle and Dispose() allocated memory (although E
  97. will do the deallocating of memory automatically, I try to be a clean
  98. programmer).
  99.  
  100. Remember.. before your ENDPROC main(), err_Dispose().
  101.  
  102. 1.5. err_Open()
  103. ---------------
  104.  
  105. VOID err_Open(VOID)
  106.  
  107. You should NEVER call this procedure.
  108.  
  109. The only thing you might consider doing to this procedure is modifying the
  110. format string appearing DEEP in a VfPrintf() statement that displays the
  111. date, time, and weekday as a sort of file-header.. you might want to
  112. change the word 'ERROR:' to the name of your program or something.
  113.  
  114. Otherwise, basically, this procedure opens a filehandler for stderr
  115. (making sure it can do so legally).  It does a lot of checking and
  116. fool-proofing, allowing you to change `stderr.filename' easily.  It also
  117. closes filehandles if you've changed stderr.filename.  It's a fairly smart
  118. procedure.  If any bugs exist in it, please let me know.
  119.  
  120. 1.6. err_WriteF(format,items)
  121. -----------------------------
  122.  
  123. VOID err_WriteF(LONG format, LONG items)
  124.  
  125. format - a bit of text to be printed out, similiar to WriteF(), but
  126.           without '\s' statements.
  127. items  - a list of numbers that you may wish to have printed according to
  128.           the format above.
  129.  
  130. Basically, this is the procedure you use to write your error messages.
  131.  
  132. Simply speaking, this statement works very similiarly to WriteF(), except
  133. that you cannot format strings, and the numbers you might format have to
  134. be in an E-list format (eg. [12,234,15,6]).  So, you must use it like:
  135.  
  136. err_WriteF('MyProg: \d cols is not enough!\nNeither is \d lines!\n',
  137.            [col,lines])
  138.  
  139. If col = 5 and lines = 2, then the above should print:
  140.  
  141.                MyProg: 5 cols is not enough!
  142.                Neither is 2 lines!
  143.  
  144. err_WriteF() will call `err_Open()', insuring it has a place to write
  145. information into.
  146.  
  147. 1.7. Possible Problems
  148. ----------------------
  149.  
  150. StdErr should generally work fairly well, but since it needs to allocate
  151. memory, and it needs to open files, there always exists the possibility
  152. that it will fail.
  153.  
  154. StdErr has been designed to be as careful of these matters as possible, but
  155. I strongly recommend any programmer using StdErr to use RAISE IF statements
  156. (with Open and New) to protect his/her program from inexplicable errors. 
  157. StdErr has been designed with error handling in these matters, with text
  158. being written via WriteF() (a most reliable way to write information)
  159. should it fail.
  160.  
  161. Use of the StdErrExample.E as a guide is recommended.
  162.  
  163. 1.8. General Pattern of Use
  164. ---------------------------
  165.  
  166. Basically, use PMODULE 'PMODULE:StdErr' in your program, then invoke
  167. it something like:
  168.  
  169. PROC main()
  170.  
  171.  DEF ...
  172.  err_New(NIL) /* stderr, as in C */
  173.  
  174.  blah blah blah
  175.  
  176.  err_WriteF('You are missing line #\d',[line]) /* error message */
  177.  
  178.  blah blah blah
  179.  
  180.  err_Dispose()
  181.  
  182. ENDPROC
  183.  
  184. 2. About The Author
  185. -------------------
  186.  
  187. I'm surprised you care!
  188.  
  189. My name is Joseph Edwards Van Riper III (although I'm generally called
  190. 'Trey').  I have written another program called 'Quip', which is a fortune
  191. cookie program that will eat your brain ... it has more features than any
  192. other fortune cookie program in existence.  A dubious honour, authoring
  193. that monster.  I've uploaded two datafiles for that program.. QuipZen and
  194. QuipMusic.
  195.  
  196. Currently, I am a junior at the University of North Carolina, Asheville,
  197. working towards my Bachelor of Arts in Music (with an emphasis on
  198. Composition).  I have one more year left here, and it would appear that I
  199. will finish with my degree in that year, totally four years of college
  200. life for me (a shorter time than some of my companions, I've noticed).
  201.  
  202. I was in the US Army as a bandsman/journalist for five years and a month,
  203. two years of which I spent in Japan (Camp Zama, for the curious).  I would
  204. care not to repeat that experience.
  205.  
  206. I type blindingly fast for a non-clerical student, and I work with
  207. computers with an intuitive feel for them; when something goes wrong, I
  208. can intuitively sense where the problem is, and find a solution.
  209.  
  210. I think computers will steal my soul if I'm not careful.
  211.  
  212. I am a vegetarian (vegan, and becoming even stricter in my eating
  213. practices), and a non-denominational Christian.
  214.  
  215. You may mail me at jvanriper@uncavx.unca.edu.  If you can find the Mosaic
  216. server at UNCA, you can poll my account for MIDI specs and more junk about
  217. myself.  You can also find me lurking around the Amiga E mailing list.
  218.  
  219. Moo.
  220.  
  221. 3. About The Program
  222. --------------------
  223.  
  224. StdErr.E was originally an idea born inside Quip.E (that is, Quip the
  225. Fortune Cookie Program from Hell, not the QWK reader).
  226.  
  227. I was having a horrible time handling my error messages.  I had some very
  228. specific needs, considering icons and stuff.  I worked out all my problems
  229. with Quip, finally getting something to work the way I wanted it to do.
  230.  
  231. Then I realized that there may be others who needed something similar to
  232. Quip's stderr handling, although reading through Quip.E to find the
  233. necessary bits of code would require someone with more patience than Job. 
  234. I thought, therefore, I should extract the core of my routines, re-form
  235. them to be simpler to use, and add a few extra nifty features.
  236.  
  237. Thus, StdErr.E was born.
  238.  
  239. StdErr, being reworked from Quip's stderr handling, works better, and is
  240. far more organized.  I attempted to follow an Object Oriented approach,
  241. despite the fact that Amiga E is not an Object Oriented language.  To this
  242. end, I used the 'err_' prefix, while using fairly common commands such as
  243. 'WriteF' and 'Open' to keep things organized and simple to understand in
  244. function.  I also created an Object, and purposely renamed one of the
  245. members in the object a value that wouldn't have as much meaning to
  246. people, since I didn't want anyone messing with it.
  247.  
  248. I decided to use 'stderr' as a global variable, because essentially nobody
  249. else should have a need for such a variable name, once these methods are
  250. employed, and it seemed to be a very easy variable name to remember.
  251.  
  252. StdErr.E has been tested, and should not leak memory or crash.  It tries
  253. to be very durable.
  254.  
  255. 4. To Do
  256. --------
  257.  
  258. The only things I can think of that would really improve this code
  259. tremendously would be:
  260.  
  261. * Allow strings to be formatted in the text.
  262.  
  263. * Include Fault() handling as an option.
  264.  
  265.